<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/11/20
 * Time: 14:30
 */

namespace app\common\service;


class IpsOriginalRule
{
    /**
     * @name 列表
     * @param $hostId
     * @param $params
     * @param $limit
     * @return array
     * @author wx
     * @date 2019/11/21 10:58
     */
    function list($hostId, $params, $limit)
    {
        $db = db('ips_original_rule')->where('host_id',$hostId)
            ->where('status', '<', 3);
        
        if(isset($params['rule']) && !empty($params['rule'])){
            $db->where('rule','like','%'.$params['rule'].'%');
        }

        $list = $db->order('id desc')->paginate($limit)->toArray();

        return $list;
    }

    /**
     * @name
     * @param $condition
     * @param $updateData
     * @return int|string
     * @author wx
     * @date 2019/11/21 10:53
     */
    function modify($condition, $updateData)
    {
        return db('ips_original_rule')->where($condition)->update($updateData);
    }

    /**
     * @name 删除
     * @param $condition
     * @return int
     * @author wx
     * @date 2019/11/21 10:58
     */
    function del($condition)
    {
        return db('ips_original_rule')->where($condition)->update(['status' => 3]);
    }

    /**
     *  清空
     */
    function clear($condition)
    {
        return db('ips_original_rule')->where($condition)->delete();
    }

    
    /**
     * @name: 查找
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-13 11:32:11
     */
    function checkRequestData ($hostId, $ruleId)
    {
        $return = db('ips_original_rule')->where('host_id', $hostId)->whereIn('id', $ruleId)->select();

        return $return;
    }
}